package sel.me.mysql.learning.config;


import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

import com.alibaba.druid.pool.DruidDataSource;

//@Configuration
public class DruidDataSourceConfig {

//	<property name="url" value="${jdbc.url}"/>
//    <property name="username" value="${jdbc.username}"/>
//    <property name="password" value="${jdbc.password}"/>
//
//    <property name="initialSize" value="${jdbc.initialSize}"/>
//    <property name="minIdle" value="${jdbc.minIdle}"/>
//    <property name="maxActive" value="${jdbc.maxActive}"/>
//
//    <property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
//    <property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
//
//    <property name="validationQuery" value="${jdbc.validationQuery}"/>
//    <property name="testWhileIdle" value="${jdbc.testWhileIdle}"/>
//    <property name="testOnBorrow" value="${jdbc.testOnBorrow}"/>
//    <property name="testOnReturn" value="${jdbc.testOnReturn}"/>
//    <property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}"/>
//    <property name="removeAbandoned" value="${jdbc.removeAbandoned}"/>
//    <property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}"/>
//    <property name="logAbandoned" value="${jdbc.logAbandoned}"/>
//
//    <property name="filters" value="${jdbc.filtes}"/>
//    
//    
//    jdbc.url=jdbc:mysql://47.96.185.2:3306/g1_futures?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
//    	jdbc.username=root
//    	jdbc.password=!QAZ2wsx#EDC4rfv
//    	#数据源配置
//    	jdbc.initialSize = 1
//    	jdbc.minIdle = 1
//    	jdbc.maxActive = 10
//
//    	jdbc.timeBetweenEvictionRunsMillis = 60000
//    	jdbc.minEvictableIdleTimeMillis = 300000
//
//    	jdbc.validationQuery = SELECT 'x'
//    	jdbc.testWhileIdle = true
//    	jdbc.testOnBorrow = false
//    	jdbc.testOnReturn = false
//    	jdbc.maxOpenPreparedStatements = -1
//    	jdbc.removeAbandoned = true
//    	jdbc.removeAbandonedTimeout = 1800
//    	jdbc.logAbandoned = true
//
//    	jdbc.filtes = stat
	
	@Bean
	public DataSource dataSource() throws SQLException {
		DruidDataSource dataSource = new DruidDataSource();
		dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull");
		dataSource.setUsername("root");
		dataSource.setUsername("root");
		dataSource.setInitialSize(1);
		dataSource.setMinIdle(1);
		dataSource.setMaxActive(10);
		dataSource.setTimeBetweenEvictionRunsMillis(60000);
		dataSource.setMinEvictableIdleTimeMillis(300000);
		dataSource.setValidationQuery("SELECT 'x'");
		dataSource.setTestWhileIdle(true);
		dataSource.setTestOnBorrow(false);
		dataSource.setTestOnReturn(true);
		dataSource.setMaxOpenPreparedStatements(-1);
		dataSource.setRemoveAbandoned(true);
		dataSource.setRemoveAbandonedTimeout(1800);
		dataSource.setLogAbandoned(true);
		dataSource.setFilters("stat");
		
		return dataSource;
	}
	
	
//	@Bean
//	@DependsOn("dataSource")
//	public SqlSessionFactory sqlSessionFactory(DataSource dataSource) {
//		SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//		sqlSessionFactoryBean.setDataSource(dataSource);
//		sessionFactory
//	}
	
	
	
	
	
}
